<?php
class KpidayReportForm extends sfFormSymfony
{
  public function configure()
  {
    $this->setWidget('plant', new sfWidgetFormDoctrineChoice(array(
                                        'model'=>'Plant', 
                                        'add_empty'=>False, 
                                        'multiple'=>True,    
                                        'query' => Doctrine_Query::create()->from('Plant p')->select('id, name')->where('enable=1')->orderBy('name ASC'),
                                         ))
                            );
    
    $this->setWidget('date', new sfWidgetFormDateRange(array(
        'from_date' => new sfWidgetFormDate(array('format'=>'%day%%month%%year%')),
        'to_date' => new sfWidgetFormDate(array('format'=>'%day%%month%%year%'))
        )));
    
    $this->setValidators(array(
        'plant'=>new sfValidatorDoctrineChoice(array(
                                        'model'=>'Plant', 
                                        'multiple'=>true,
                                        'query' => Doctrine_Query::create()->from('Plant p')->select('id, name')->where('1'),
                                        )),
        
        'date'      => new sfValidatorDateRange(array(
                                                'required'=>true,
                                                'from_date' => new sfValidatorDate(array('required' => true,'datetime_output' => 'd-m-Y')),
                                                'to_date'   => new sfValidatorDate(array('required' => true,'datetime_output' => 'd-m-Y')),
                                        )),
        ));                   
    
    $this->widgetSchema->setHelp("plant","One or more plants for the report ");
    $this->widgetSchema->setHelp("date","Select dates range");
    
    $this->widgetSchema->setNameFormat('kpiDay[%s]');
  }  
}

